package com.neuedu.nep.controller;

import com.neuedu.nep.base.BaseController;
import com.neuedu.nep.base.R;
import com.neuedu.nep.dto.AdminPageDTO;
import com.neuedu.nep.dto.AqiFeedBackAddDTO;
import com.neuedu.nep.model.AqiFeedback;
import com.neuedu.nep.service.AqiFeedBackService;
import com.neuedu.nep.vo.FeedBackInfoVO;
import com.neuedu.nep.vo.PageVO;
import com.neuedu.nep.vo.ShowFeedbackVO;
import com.neuedu.nep.vo.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 黄宇佳
 * @create 2024-04-10 15:59
 * @description:
 */
@RestController
@CrossOrigin
@RequestMapping("AqiFeedBack")
public class AqiFeedBackController extends BaseController {
    @Resource
    private AqiFeedBackService aqiFeedBackService;

    @PostMapping("add")
    public R add(@RequestBody AqiFeedBackAddDTO aqiFeedBackAddDTO){
        UserVO userVO=user();
        String telId=userVO.getTelId();
        aqiFeedBackAddDTO.setTelId(telId);
        AqiFeedback aqiFeedback=new AqiFeedback();
        BeanUtils.copyProperties(aqiFeedBackAddDTO,aqiFeedback);
        int result = aqiFeedBackService.addAqiFeedBack(aqiFeedback);
        if (result==2){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @GetMapping("supervisorPage")
    public R supervisorPage(@RequestParam Integer lastItemId,@RequestParam Integer pageSize){
        UserVO userVO=user();
        String telId=userVO.getTelId();
        List<ShowFeedbackVO> list = aqiFeedBackService.page(telId, lastItemId, pageSize);
        return R.ok().setResult("feedbacks",list);
    }

    @GetMapping("gridmemberPage")
    public R gridmemberPage(@RequestParam Integer lastItemId,@RequestParam Integer pageSize){
        UserVO userVO=user();
        Integer gmId=userVO.getGmId();
        List<ShowFeedbackVO> list = aqiFeedBackService.page(gmId, lastItemId, pageSize);
        return R.ok().setResult("feedbacks",list);
    }

    @PostMapping("adminPage")
    public R adminPage(@RequestBody AdminPageDTO adminPageDTO){
        PageVO<ShowFeedbackVO> page = aqiFeedBackService.page(adminPageDTO);
        return R.ok().setResult("page",page);
    }

    @GetMapping("feedbackInfo")
    public R feedbackInfo(@RequestParam Integer afId){
        FeedBackInfoVO feedBackInfo = aqiFeedBackService.getFeedBackInfo(afId);
        return R.ok().setResult("feedBackInfo",feedBackInfo);
    }

    @GetMapping("setGmIdToFeedback")
    public R setGmIdToFeedback(@RequestParam Integer afId,@RequestParam Integer gmId){
        int result = aqiFeedBackService.setGmIdToFeedback(afId, gmId);
        if(result==2){
            return R.ok("指派成功");
        }else {
            return R.ok("指派失败");
        }
    }
}
